<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @copyright essentialmind.com 2005
    *
    *********************************************************/

    /***
    * class ajaxAddNode
    ****
    * This class will create a new node via an AJAX method
    ****
    * @package ajax
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @copyright essentialmind.com 2005
    ***/
    class ajaxAddPredefinedPackageToCart extends ajaxAction{

        public function process(){   
            if(!$_SESSION['CART'] or ($_SESSION['CART'] and !is_object($_SESSION['CART']))){
                $_SESSION['CART'] = new shoppingCart($this->db);
            }
            
            $this->r->itemsBefore = $_SESSION['CART']->count();
            
            $arts = $this->db->getCol("SELECT article_id FROM node_shop_package_article WHERE package_id = ".(int)$_REQUEST['id']);
            
            $returnItems = array();            
            foreach($arts as $item){
                $item = str_replace('art_','',$item);
                if(!$_SESSION['CART']->items[$item]){
                    $_SESSION['CART']->addItem((int)$item,(int)$_REQUEST['q1'],(int)$_REQUEST['q2']);                                        
                    $returnItems[] = $_SESSION['CART']->item((int)$item);
                }
            }            
            
            $this->r->items     = $returnItems;
            $this->r->sum       = number_format($_SESSION['CART']->sum(),2,'.','');
            $this->r->discount  = $_SESSION['CART']->discount();
            $this->r->total     = number_format($_SESSION['CART']->price(),2,'.','');
        }
    }
?>